#include "SDL2/SDL.h"

#include "KeyEvent.h"
#include "MenuState.h"
#include "ClientGamePlayState.h"
#include "ServerGamePlayState.h"

KeyEvent::KeyEvent(int code)
        : code(code)
{
}

KeyEvent::~KeyEvent()
{
}

GameState* KeyEvent::visitMenuState(MenuState* menuState) const
{
    switch (code)
    {
    case SDLK_1:
        return menuState->performMenuAction1();

    case SDLK_2:
        return menuState->performMenuAction2();

    case SDLK_3:
        return menuState->performMenuAction3();

    case SDLK_ESCAPE:
        return menuState->performMenuActionEscape();

    case SDLK_BACKSPACE:
        return menuState->performMenuActionBackspace();

    case SDLK_RETURN:
        return menuState->performMenuActionReturn();

    default:
        return NULL;
    }
}

GameState* KeyEvent::visitGamePlayState(GamePlayState* gamePlayState) const
{
    switch (code)
    {
    case SDLK_LEFT:
        return gamePlayState->handleLeftKey();

    case SDLK_RIGHT:
        return gamePlayState->handleRightKey();

    case SDLK_DOWN:
        return gamePlayState->handleDownKey();

    case SDLK_UP:
        return gamePlayState->handleUpKey();

    case SDLK_SPACE:
        return gamePlayState->handleSpaceKey();

    case SDLK_ESCAPE:
        return gamePlayState->leaveGame();

    default:
        return NULL;
    }
}
